/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "register/graph_optimizer/fusion_common/fusion_config_info.h"
#include "mmpa/mmpa_api.h"
#include "graph/debug/ge_log.h"

namespace fe {
namespace {
constexpr char const *kEnableNetworkAnalysis = "ENABLE_NETWORK_ANALYSIS_DEBUG";
}
FusionConfigInfo::FusionConfigInfo() : is_init_(), is_enable_network_analysis_(false) {}
FusionConfigInfo::~FusionConfigInfo() {}

FusionConfigInfo& FusionConfigInfo::Instance() {
  static FusionConfigInfo fusion_config_info;
  return fusion_config_info;
}

Status FusionConfigInfo::Initialize() {
  if (is_init_) {
    return SUCCESS;
  }

  InitEnvParam();
  is_init_ = true;
  return SUCCESS;
}

void FusionConfigInfo::InitEnvParam() {
  char env_value[MMPA_MAX_PATH];
  INT32 ret = mmGetEnv(kEnableNetworkAnalysis, env_value, MMPA_MAX_PATH);
  if (ret == EN_OK) {
    std::string env_str_value = std::string(env_value);
    GELOGD("The value of env[%s] is [%s].", kEnableNetworkAnalysis, env_str_value.c_str());
    is_enable_network_analysis_ = std::atoi(env_str_value.c_str());
  }
  GELOGD("Enable network analysis is [%d].", is_enable_network_analysis_);
}

Status FusionConfigInfo::Finalize() {
  is_init_ = false;
  is_enable_network_analysis_ = false;
  return SUCCESS;
}

bool FusionConfigInfo::IsEnableNetworkAnalysis() const {
  return is_enable_network_analysis_;
}
}
